

$.fn.dropIn = function (scrollHeight) {
	return this.each(function () {
		var item = $(this);
		var offset = item.outerHeight();
		item.css({'position':'absolute','left':0,'top':-offset}).show();
		item.up = true;
		$(window).scroll(function(e){
			try {
				var scrollTop = $(window).scrollTop();
				if (item.up && scrollTop > scrollHeight) {
					item.stop().animate({top: 0},100);
					item.up = false;
				} else if (!item.up && scrollTop < scrollHeight){
					item.stop().animate({top:-offset},100);
					item.up = true;
				}
			} catch (e) {}
		});
	});
}

$.fn.entryOptions = function () {
	var menus = this;
	$("html").click(function() {
		menus.removeClass('active');
	});
	return this.each(function () {
		$(this).bind('click', function (e) {
			try {
				e.stopPropagation();
				e.preventDefault();
				//hiding drop down menu when it is clicked again
				if ($(this).hasClass('active')) {
					$(this).removeClass('active');
				} else {
					//displaying the drop down menu
					menus.removeClass('active');
					$(this).addClass('active');
				}
			} catch (e) {}
		});
	});
}

$.fn.timePicker = function () {
	var prevTemplate = '<div id="time-shift-left"><a href="#">&laquo; Previous Week</a></div>';
	var nextTemplate = '<div id="time-shift-right"><a href="#">Next Week &raquo;</a></div>';
	return this.each(function () {
		var timepicker = $(this);
		var calendar = $(this).find('.calendar>:first-child');
		var template = calendar.html(); //this has to change to get new appointment times
		$(prevTemplate).appendTo(timepicker).click(function(e){
			calendar.width(calendar.width()+550);
			var position = calendar.position().left;
			calendar.prepend(template).css('left',position-550).animate({left: position},400);
		});
		$(nextTemplate).appendTo(timepicker).click(function(e){
			calendar.width(calendar.width()+550);
			var position = calendar.position().left-550;
			calendar.append(template).animate({left: position},400);
		});
	});
}


$.fn.stickyside = function() {
	return this.each(function () {
		var sidebar = $(this),
			offset = $(this).offset();
		$(window).scroll(function() {
			if ($(window).scrollTop() > offset.top - 10) {
				sidebar.addClass('fixed');
			} else {
				sidebar.removeClass('fixed');
			}
		});
	});
}	
